package day19

import org.apache.flink.api.scala._


object FlinkWCScala {

  def main(args: Array[String]): Unit = {

    // 构建环境（初始化环境）//注意scala一定要导入flink.scala的包。import org.apache.flink.api.scala.ExecutionEnvironment
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    // 将字符串生成数据集
    val text: DataSet[String] = env.fromElements(
      "hello zhangsan",
      "hello lisi",
      "hello wangwu"
    )
    // 处理数据:将tup(a,b)中的第1个来进行groupBy(0)分组，分完组后以(a,b)中的第2个即sum(1)进行汇总sum(1)
    // 简单说就是以k分组，分好组好，将v相加汇总。
    val sumed: AggregateDataSet[(String, Int)] = text.flatMap(_.split(" ")).map((_, 1)).groupBy(0).sum(1)

    sumed.print()
  }

}
